package org.jeecg.modules.wms.service.impl;

import org.jeecg.modules.wms.entity.WmsOutboundDetail;
import org.jeecg.modules.wms.mapper.WmsOutboundDetailMapper;
import org.jeecg.modules.wms.service.IWmsOutboundDetailService;
import org.jeecg.modules.wms.vo.WmsOutboundDetailVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.Date;
import java.util.List;

/**
 * @Description: 出库单明细服务实现类
 * @Author: jeecg-boot
 * @Date: 2023-07-01
 * @Version: V1.0
 */
@Service
public class WmsOutboundDetailServiceImpl extends ServiceImpl<WmsOutboundDetailMapper, WmsOutboundDetail> implements IWmsOutboundDetailService {
    
    @Override
    public List<WmsOutboundDetail> selectByOutboundId(String outboundId) {
        return baseMapper.selectByOutboundId(outboundId);
    }
    
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteByOutboundId(String outboundId) {
        return baseMapper.deleteByOutboundId(outboundId) >= 0;
    }
    
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean saveBatch(String outboundId, List<WmsOutboundDetail> outboundDetailList) {
        if (outboundDetailList == null || outboundDetailList.isEmpty()) {
            return true;
        }
        
        Date now = new Date();
        for (WmsOutboundDetail detail : outboundDetailList) {
            // 设置出库单ID
            detail.setOutboundId(outboundId);
            // 设置初始状态为待出库
            detail.setStatus("0");
            // 设置创建时间
            if (detail.getCreateTime() == null) {
                detail.setCreateTime(now);
            }
        }
        
        return saveBatch(outboundDetailList);
    }

    @Override
    public List<WmsOutboundDetail> selectByOutboundIdAndUpdateBy(String id, String username) {
        return baseMapper.selectByOutboundIdAndUpdateBy(id,username);
    }
} 